﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace DesignPatternsDemo
{
    class Program
    {
        static void Main(string[] args)
        {
            // signleton pattern
            Console.WriteLine("Demonstrating singleton pattern ...");

            Singleton singleton = Singleton.GetInstance();
            Singleton singleton2 = Singleton.GetInstance();

            if (singleton == singleton2)
            {
                Console.WriteLine("singleton and singleton2 are the same, bcs it's singleton pattern");
            }

            // factory pattern
            Console.WriteLine("\nDemonstrating factory pattern ...");

            IProduct product1 = Factory.GetProduct(Factory.ProductType.Fridge);
            IProduct product2 = Factory.GetProduct(Factory.ProductType.Dishwasher);

            product1.Use();
            product2.Use();

            // facade pattern
            Console.WriteLine("\n: Demonstrating facade pattern ...");
            Facade.Customer customer = new Facade.Customer("Jacob", "UC");
            Facade.Product product = new Facade.Product("Pot", "Made in China");
            Facade.OrderFacade facade = new Facade.OrderFacade(customer, product);

            Console.WriteLine("Order details: (retrieved through facade");
            Console.WriteLine("Customer: Name: {0}, Address: {1}",
                facade.GetCustomerName(), facade.GetAddress());
            Console.WriteLine("Product: Name: {0}, Description: {1}",
                facade.GetProductName(), facade.GetDescription());

            // adapter pattern
            Console.WriteLine("\n: Demonstrating adapter pattern ...");
            DateTime date = DateTime.Now;
            DateAdapter adapter = new DateAdapter(date);
            Console.WriteLine("Formatted date 1: {0}", adapter.GetDateSepByDash());
            Console.WriteLine("Formatted date 2: {0}", adapter.GetDateSepBySlash());

            // proxy pattern
            Console.WriteLine("\n: Demonstrating proxy pattern ...");
            Proxy.SampleProxy proxy = new Proxy.SampleProxy();
            string request = "request from local";
            Console.WriteLine("the request is: \n\"{0}\"", request);
            string reply = proxy.ServiceMethod(request);
            Console.WriteLine(": the reply from the service (server) is: \n\"{0}\"", reply);

            // observer pattern
            Console.WriteLine("\n: Demonstrating observer pattern ...");
            Observer.EventSource.Demo();
            Console.WriteLine(": End of Event Source Demo");

            // builder pattern
            Console.WriteLine("\n: Demonstrating builder pattern ...");
            Builder.Product.Builder builder = new Builder.Product.Builder("Car");
            builder.SetManufacturer("Toyota");
            builder.SetDescription("2000");
            Builder.Product builtProduct = builder.Build();
            Console.WriteLine("The details of the product that has been built:");
            Console.WriteLine("Name: {0}", builtProduct.Name);
            Console.WriteLine("Manufacturer: {0}", builtProduct.Manufacturer);
            Console.WriteLine("Description: {0}", builtProduct.Description);


        }
    }
}
